package p1TopN;


import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

//记住，MapReduce的输入输出是针对于文件夹而言的。系统会自动将目标文件夹作为一个输入。
public class AverageTempBean implements WritableComparable<AverageTempBean> {
    //private String date;      //日期
    private double at;        //AverageTemperature平均温度
    private double atu;       //AverageTemperatureUncertainty平均温度可靠度
    private String city;      //所在城市
    private String country;   //国家
    private String latitude;  //纬度
    private String longitude; //经度

    public AverageTempBean() {
    }

    @Override
    public int compareTo(AverageTempBean o) {
        if (this.at>o.at){
            return -1;    //this比比较对象大，按理说应该返回一个正数，这样this就不在比较对象的后面，从而是升序排序，但是此处返回了一个正数，则是故意想要降序排序
        }else if (this.at<o.at){
            return 1;
        }
        return 0;   //空有一个0则全部一样，这有一个1则全部不一样。
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeDouble(at);
        dataOutput.writeDouble(atu);
        dataOutput.writeChars(city+',');
        dataOutput.writeChars(country+',');
        dataOutput.writeChars(latitude+',');
        dataOutput.writeChars(longitude);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        at=dataInput.readDouble();
        atu=dataInput.readDouble();
        String ss;
        ss=dataInput.readLine();
        String[] fields=ss.split(",");
        city=fields[0];
        country=fields[1];
        latitude=fields[2];
        longitude=fields[3];

    }

    @Override
    public String toString() {
        return  ","+at+","+atu +","+city+","+country+","+latitude+","+longitude;
    }

    public AverageTempBean(double at, double atu, String city, String country, String latitude, String longitude) {
        this.at = at;
        this.atu = atu;
        this.city = city;
        //this.date = date;
        this.country = country;
        this.latitude = latitude;
        this.longitude = longitude;
    }

    public double getAt() {
        return at;
    }

    public void setAt(double at) {
        this.at = at;
    }

    public double getAtu() {
        return atu;
    }

    public void setAtu(double atu) {
        this.atu = atu;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }


    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public void set(double at,double atu,String city,String country,String latitude,String longitude){
        this.at=at;
        this.atu=atu;
        this.city=city;
        this.country=country;
        this.latitude=latitude;
        this.longitude=longitude;
    }
}
